//
//  HJYTabBarController.m
//  BuDeJie
//
//  Created by 胡大力 on 2016/12/5.
//  Copyright © 2016年 nebula. All rights reserved.
//

#import "HJYTabBarController.h"
#import "HJYNavController.h"

#import "HJYEssenceVC.h"
#import "HJYNewVC.h"
#import "HJYPublishVC.h"
#import "HJYFriendTrendVC.h"
#import "HJYMineTableVC.h"

@interface HJYTabBarController ()

@property (nonatomic, weak) UIButton *publishBtn;

@end

@implementation HJYTabBarController

+ (void)load {
    
    //更改tabBar button的字体大小
    //利用appearance修改这个类的所有对象的外观
    UITabBarItem *tabBarItem = [UITabBarItem appearance];
    
    NSMutableDictionary *attribu = [NSMutableDictionary dictionary];
    
    attribu[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    
    [tabBarItem setTitleTextAttributes:attribu forState:UIControlStateNormal];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置tabBar主题颜色
    self.tabBar.tintColor = [UIColor colorWithWhite:0 alpha:0.7];
    //设置tabBar的背景图片
    self.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-light"];
    
    //添加所有子控制器
    [self setUpAllChildController];
    //设置子控制器的button
    [self setUpAllTarBarButtons];
    
    //懒加载publish按钮,并设置位置
    self.publishBtn.center = CGPointMake(self.tabBar.bounds.size.width * 0.5, self.tabBar.bounds.size.height * 0.5);
    
    
}

//懒加载publishBtn
- (UIButton *)publishBtn {
    
    if (_publishBtn == nil) {
        UIButton *publishBtn = [UIButton buttonWithType: UIButtonTypeCustom];
        _publishBtn = publishBtn;
        
        [publishBtn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishBtn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [publishBtn sizeToFit];
        
        [publishBtn addTarget:self action:@selector(publishBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self.tabBar addSubview:publishBtn];
    }
    
    return _publishBtn;
}

- (void)publishBtnClick {
    
}


- (void)setUpAllTarBarButtons {
    
    //1.设置精华 图标与文字
    UINavigationController *nav0 = self.childViewControllers[0];
    nav0.tabBarItem.title = @"精华";
    nav0.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    nav0.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
    
    //2.设置新帖 图标与文字
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"新帖";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    nav1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"];
    
    //3.发布控制器 关闭页面跳转
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.enabled = NO;
    
    //4.设置关注 图标与文字
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"关注";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    nav3.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
    
    //5.设置我的 图标与文字
    UINavigationController *nav4 = self.childViewControllers[4];
    nav4.tabBarItem.title = @"我";
    nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    nav4.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"];
    
    
}

- (void)setUpAllChildController {
    
    
    //1.精华控制器
    HJYEssenceVC *vc0 = [[HJYEssenceVC alloc] init];
    vc0.view.backgroundColor = [UIColor grayColor];
    
    HJYNavController *nav0 = [[HJYNavController alloc] initWithRootViewController:vc0];
    [self addChildViewController:nav0];
    
    //2.新帖控制器
    HJYNewVC *vc1 = [[HJYNewVC alloc] init];
    vc1.view.backgroundColor = [UIColor greenColor];
    
    HJYNavController *nav1 = [[HJYNavController alloc] initWithRootViewController:vc1];
    [self addChildViewController:nav1];
    
    //3.发布控制器
    HJYPublishVC *vc2 = [[HJYPublishVC alloc] init];
    vc2.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController:vc2];
    
    //4.关注控制器
    HJYFriendTrendVC *vc3 = [[HJYFriendTrendVC alloc] init];
    vc3.view.backgroundColor = [UIColor blueColor];
    
    HJYNavController *nav3 = [[HJYNavController alloc] initWithRootViewController:vc3];
    [self addChildViewController:nav3];
    
    //5.我的控制器
    HJYMineTableVC *vc4 = [[HJYMineTableVC alloc] init];
    vc4.view.backgroundColor = [UIColor blackColor];
    
    HJYNavController *nav4 = [[HJYNavController alloc] initWithRootViewController:vc4];
    [self addChildViewController:nav4];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
